package com.jinboe.product.dao.impl;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;

import com.jinboe.comm.dao.impl.BaseDaoImpl;
import com.jinboe.product.dao.ProductDao;
import com.jinboe.product.dto.ProductDto;
import com.jinboe.product.util.ProductConstants;

public class ProductDaoImpl extends BaseDaoImpl implements ProductDao{
	private String queryProductSql="select product.*,baseInfo.* from YB_PRODUCT product where 1=1  "+
		"left join YB_BASE_INFO baseInfo on baseInfo.MAININFOID=product.ID " +
		"where 1=1  ";
	@Override
	public int insertProduct(ProductDto productDto) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public List<ProductDto> queryProduct(Map conMap, int startNum, int endNum) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<ProductDto> queryProduct(Map conMap) {
		// TODO Auto-generated method stub
		List<ProductDto> orderItemList=new ArrayList();
		String sql=createProductWhereConSql(queryProductSql, conMap);
		List queryList = getJdbcTemplate().queryForList(sql);
		Iterator iterator = queryList.iterator();
		while (iterator.hasNext()) {
			Map queryIteratorMap = (Map) iterator.next();
			ProductDto productDto=new ProductDto();
			createDto(productDto, queryIteratorMap);
			orderItemList.add(productDto);
		}
		return orderItemList;
	}
	private String createProductWhereConSql(String queryListSql,Map conMap){
		String sql = createBaseWhereConSql(queryListSql, conMap);
		String categoryId=(String)conMap.get(ProductConstants.KET_NAME_CATEGORYID);
		if(StringUtils.isNotBlank(categoryId)){
			sql+=" and  product.categoryId='"+categoryId.trim()+"' ";
		}
		
		return sql;
	}
	@Override
	public int queryProductCount(Map conMap) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int updateProduct(ProductDto productDto) {
		// TODO Auto-generated method stub
		return 0;
	}
	
	

}
